#include <bits/stdc++.h>

using namespace std;
class Solution
{
public:
    int numFriendRequests(vector<int> &ages)
    {
        int ret = 0;
        queue<int> q;
        q.push(ages[0]);
        sort(ages.begin(), ages.end());
        for (int i = 1; i < ages.size(); ++i)
        {
            if (ages[i] > 100)
            {
                while (!q.empty() && q.front() < 100)
                {
                    q.pop();
                }
            }
            while (!q.empty() && q.front() <= ages[i] * 0.5 + 7)
            {
                q.pop();
            }
            ret += q.size();
            q.push(ages[i]);
        }
        return ret;
    }
};